<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {

	public function _initialize()
    {
        //未登录、登录超时、长时间未动
    	if (empty($_SESSION['adminid']) || time() > $_SESSION['adminovertime'] || empty($_SESSION['adminovertime']) ) {

    		$this->redirect('/admin.php/Common/login');
    	}

        session('adminovertime',(time()+60*60*C('adminovertime')));

    }

	public function Index(){
		$adminid = $_SESSION['adminid'];
        
        $m_admin = M('Admin');
        $where['id'] = $adminid;

        $adminInfo = $m_admin->where($where)->find();

        $this->assign('adminInfo',$adminInfo);
		$this->display();
	}


    /**
     * [setting 参数设置]
     * @return [type] [description]
     */
    public function setting(){
        $this->display();
    }

    public function ctrl_setval(){
        if (IS_AJAX) {
            $filename = $_SERVER['DOCUMENT_ROOT'] . '/Application/Common/Conf/setval.php';
            $res = file_put_contents($filename, strip_whitespace("<?php\treturn " . var_export($_POST, true) . ";?>"));


            if($res){
                $this->ajaxReturn(array(
                    'code'=>1,
                    'msg' => '保存成功'
                ));
           }else{
                $this->ajaxReturn(array(
                    'code'=>0,
                    'msg' => '保存失败'
                ));
           }
        }else{
            $this->redirect('/admin.php/Common/BadRequest');
        }
    }

	public function main(){
		$this->display();
	}
}